package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.DeptMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Dept;
import com.itheima.pojo.Emp;
import com.itheima.service.DeptService;
import com.itheima.service.EmpService;
import com.itheima.utils.NotDeleteException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.events.Event;

import java.time.LocalDateTime;
import java.util.List;
@Slf4j
@Service
//@Scope("prototype")
public class DeptServiceImpl extends ServiceImpl<DeptMapper,Dept> implements DeptService {
    @Autowired
    private EmpMapper empMapper;
    @Override
    public void deleteById(Integer id) {
        LambdaQueryWrapper<Emp> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Emp::getDeptId, id);
        Long num = empMapper.selectCount(queryWrapper);
        if(num>0){
            throw new NotDeleteException("部门下有员工不能删除");
        }
        removeById(id);
    }

}
